package com.jiezuo.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* @description   添加自定义拦截器
* @author        庞留杰
* @date          2020/7/16 19:18
* @version       V1.0
**/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    //静态资源存放路径
    @Value("${file.file-save-path}")
    public String filePath;
    //静态资源访问前缀
    @Value("${file.visit-prefix}")
    public String visitPrefix;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器，配置拦截地址
//        registry.addInterceptor(authInterceptor).addPathPatterns("/**")
//              .excludePathPatterns("/modeler/**","/app/rest/**");//排除这些路径，flowable modeler中的静态资源
    }

    //访问静态资源
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //其中OTA表示访问的前缀。"file:D:/OTA/"是文件真实的存储路径
        registry.addResourceHandler("/"+visitPrefix+"/**").addResourceLocations("file:"+filePath);
        //flowable静态资源
        registry.addResourceHandler("/modeler/**").addResourceLocations("classpath:/modeler/");
    }
}